<?php

use think\facade\Route;
use think\facade\Request;

$version = Request::header('version', 'v1');#接口版本
Route::group('', function () use ($version) {
    /**
     * 登录
     * 注册
     */
    Route::group('site', function () use ($version) {
        Route::post('login', "api/{$version}.Site/login");
        Route::post('reg', "api/{$version}.Site/register");
    });

    Route::group('pro', function () use ($version) {
        Route::post('get-info', "api/{$version}.pro/getinfo");
    });

    //课程推荐
    Route::group('course', function () use ($version) {
        Route::get('index', "api/{$version}.Course/index");
    })->middleware('checkLogin');

    //随机组卷
    Route::group('topic', function () use ($version) {
        Route::get('index', "api/{$version}.Topic/topic");
        Route::post('create', "api/{$version}.Topic/create");
    });//->middleware('checkLogin');

    /**
     * 会员管理
     */
    Route::group('member', function () use ($version) {
        Route::get('get-info', "api/{$version}.Member/getInfo");
    })->middleware('checkLogin');

    /**
     * 个人中心
     */
    Route::group('student', function () use ($version) {
        Route::get('index', "api/{$version}.Student/index");
    })->middleware('checkLogin');
    //首页
    Route::group('index', function () use ($version) {
        Route::get('index', "api/{$version}.Index/index");
    })->middleware('checkLogin');

    //广告位
    Route::group('Advertise', function () use ($version) {
        //首页广告位
        Route::get('index', "api/{$version}.Advertise/index");
        //历年考卷广告位
        Route::get('years', "api/{$version}.Advertise/years");
        //课程推荐广告位
        Route::get('course', "api/{$version}.Advertise/course");
    })->middleware('checkLogin');

    //个人中心--我的收藏
    Route::group('Collect', function () use ($version) {
        Route::get('index', "api/{$version}.Collect/index");
    })->middleware('checkLogin');

    //个人中心--历史答卷
    Route::group('Record', function () use ($version) {
        Route::get('index', "api/{$version}.Record/index");
    })->middleware('checkLogin');

    //训练中心--模拟考试
    Route::group('Practice', function () use ($version) {
        //模拟考试
        Route::get('index', "api/{$version}.Practice/index");
        //试卷名称
        Route::post('create', "api/{$version}.Practice/create");
    })->middleware('checkLogin');

    //历年考卷
    Route::group('paper', function () use ($version) {
        Route::get('index', "api/{$version}.Paper/index");
    })->middleware('checkLogin');

})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST',
    'Access-Control-Allow-Headers' => 'content-type,token,version',
    'Access-Control-Allow-Credentials' => 'true'
]);